<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class info_model extends CI_Model {

    public $phone_number;
    public $email;
    public $address;
    public $slides;
    public $latest_images;
    public $collections;
    public $latest_collections;
    public $working_hours;
    public $welcome;
    
    private function get_slides_db()
    {
        $data = $this->tdatabase->get_entry('slide');
        $this->slides = array();
        foreach ($data as $slide) {
            $this->slides[] = array('img'=> "uploads/images/data/slide/" . $slide->image);
        }
    }
        
    private function get_latests_db()
    {
        $this->latest_images = $this->images->getLatestImagesHTMLBox(8);
    }
    
    private function get_collections ()
    {
        $collDB = $this->tdatabase->get_entry('collections');
        foreach ($collDB as $coll) {
            $this->collections[] = array(
                'title' => $coll->title, 
                'id' => $coll->id, 
                'html' => $this->smarty->fetch('collection/collectionBox.tpl', array('collection' => $coll))
            );
        }
    }
    
    private function get_latest_collections() {
        $collHTML = "";
        $collDB = array_slice(array_reverse($this->tdatabase->get_entry('collections')), 0, 3);
        foreach ($collDB as $coll) {
            $data['collection'] = $coll;
            $collHTML .= $this->smarty->fetch('collection/collectionBox_white_bg.tpl', $data);
        }
        $this->latest_collections = $collHTML;
    }
    
   	public function __construct()
    {
        parent::__construct();// a must for constructor
        $this->load->model('images_model', 'images');
        // Phone number
		$db_data = $this->tdatabase->get_entry('contacts');
		if (isset($db_data[0])) {
            $db_data = $db_data[0];
            $this->phone_number = $db_data->phone;
            $this->email = $db_data->email;
            $this->address = $db_data->address;
            $this->working_hours = $db_data->working_hours;
            $this->welcome = $db_data->welcome;
        }
        $this->get_slides_db();
        $this->get_latests_db();
        $this->get_collections();
        $this->get_latest_collections();
    }
}



